/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2018-2019.
 * Description: add fiq header file
 * Author: jiangfeng xiao
 * Create: 2018-11-06
 */

#ifndef __LINUX_HAL_FIQ_GLUE_H
#define __LINUX_HAL_FIQ_GLUE_H

#include <asm/ptrace.h>
#include <linux/seq_file.h>
#include <linux/threads.h>

#define ERR_CALLBACK_EXIST	(1)	/* callback function already exits */
#define ERR_DTS_PARSE		(2)	/* parse dts error */

extern bool entry_fiq_mode;

#ifdef CONFIG_RTOS_HAL_FIQ_GLUE_EARLY
#define EARLY_FIQ_REGISTER_BEFORE 1
#define EARLY_FIQ_REGISTER_DONE 2
#define EARLY_FIQ_UNREGISTER 3
#define EARLY_FIQ_DISABLED 4
extern int g_fiq_early_mode;
#endif

#ifdef CONFIG_FIQ_GLUE
/* Under the hisi platform prefer hisi_request_fiq to request_fiq,
 * so that you don't have to pay attention to the fiq no.
 */
int request_fiq(void (*fiq_callback_func)(unsigned int),
	unsigned int fiq_num);

int free_fiq(void (*fiq_callback_func)(unsigned int),
	unsigned int fiq_num);

int free_fiq_all(unsigned int fiq_num);

void early_fiq_lastword_init(void);

struct pt_regs *fiq_get_regs(void);

#define receive_fiq()		entry_fiq_mode

#ifdef CONFIG_X86
#define FIQ_NMI_NUM 2
#define FIQ_TARGET 1
void fiq_register_handler(int (*enable_nmi)(void),
	void (*disable_nmi)(void),
	unsigned int (*get_nmi_cause)(void),
	void (*fiq_post_callback)(void));
#endif

#ifndef CONFIG_X86
int hisi_request_fiq(void (*fiq_callback_func)(unsigned int));

int hisi_free_fiq(void (*fiq_callback_func)(unsigned int));
#endif

#else /* CONFIG_FIQ_GLUE */
static inline int request_fiq(void (*fiq_callback_func)(unsigned int), unsigned int fiq_num)
{
	return -ENOSYS;
}

static inline int free_fiq(void (*fiq_callback_func)(unsigned int), unsigned int fiq_num)
{
	return 0;
}

static inline int free_fiq_all(unsigned int fiq_num)
{
	return 0;
}

static inline struct pt_regs *fiq_get_regs(void)
{
	return NULL;
}

#define receive_fiq()		0

#ifdef CONFIG_X86
static void fiq_register_handler(int (*enable_nmi)(void),
	void (*disable_nmi)(void),
	unsigned int (*get_nmi_cause)(void),
	void (*fiq_post_callback)(void))
{
}
#endif

#ifndef CONFIG_X86
static inline int hisi_request_fiq(void (*fiq_callback_func)(unsigned int))
{
	return -ENOSYS;
}

static inline int hisi_free_fiq(void (*fiq_callback_func)(unsigned int))
{
	return 0;
}
#endif

#endif /* CONFIG_FIQ_GLUE */


#if (NR_CPUS > 32)
#define FIQ_CPUS_MAX NR_CPUS
#else
#define FIQ_CPUS_MAX 32
#endif

#ifdef CONFIG_FIQ_GLUE_DFX
void fiq_get_checksum(uint64_t *old_crc, uint64_t *new_crc);
#endif

int fiq_print_callbacks(void (*print_func)(const char*, ...) __printf(1, 2));

#endif /* __LINUX_HAL_FIQ_GLUE_H */

